$(document).ready(function(){
	var happy = {
	    check_account: function (val) {
	      	var payment_amount = $("input[name='payment_amount']").val();
			
			console.log('checking  for '+val);
			var flag = 0;

			$.post('ajax.php', {payment_amount:payment_amount, payers_account:val,}, function(data){
				if(data === 'valid'){
					console.log('valid');
					flag = 1;
				}
				else if(data === 'invalid'){
					console.log('invalid');
					return flag;
				}
			});
	    }
	};

	var form = $("#account_validation_form");

	form.isHappy({
	   fields: {
		      '#payment_amount': {
		        required: true,
		        message: 'Not an amount',
		      },
		      '#payment_account': {
		        required: true,
		        message: 'Please enter a valid account number',
		      },
		},
	    submitButton: "#account_validation_submit"
	}).submit(function (event) {
	    console.log("Submitting form...");
	});

	$("button#account_validation_submit").click(function () {
	    form.submit();
	});
});



